473,468 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

image button rollover

i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?

Mar 14 '07 #1
2 8777
On Mar 14, 6:25 am, "smokeyd" <tom_bur...@umbro.co.ukwrote:
i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?
I did it on the server side, while I was setting up the page. Most of
my pages have an OK button and a Cancel button. For consistency's
sake, the images are all named the same. That is, the standard buttons
end in ".jpg" and the hover style ends in "_hover.jpg".

We use ImageButton controls to represent buttons so that we can
respond to click events server-side. When I'm designing the form, I
always only set the ImageUrl property, and I always only set it to the
*unhovered* image.

I wrote a method in the page's base class called SetButtonImages, that
looks something like this:

Protected Sub SetButtonImages(ByVal button As ImageButton)

Dim imageUrl As String

imageUrl = button.imageUrl

' Set the image that appears when the user moves the mouse off
' of the button.
image.Attributes.Add("onmouseout", "src=""" & imageUrl & """")

' Remove the .jpg extension, and add the "_hover.jpg" extension
imageUrl = imageUrl.SubString(0, imageUrl.Length - 4)
imageUrl &= "_hover.jpg"

' Set the image that appears when the user hovers the mouse
' over the image button.
button.Attributes.Add("onmouseover", "src=""" & imageUrl & """")

End Sub

(WARNING: I'm recalling this from memory, since the boss just tweaked
our firewall, and I can't peak at the source code to refresh my
memory, so I'm sorry if there are bugs.)

The method is invoked in the derived pages, like this:

Protected Sub PageLoad(ByVal sender As Object, ByVal e As EventArgs)
Handles Page.Load
...
SetButtonImages(btnOk)
SetButtonImages(btnCancel)
End Sub

This implementation saved me a lot of time, but it's based on a base
class for your pages. If you're not using a base class, you can simply
put the SetButtonImages function in a sepraate class, or even in a
module and invoke it from there (so that you don't have to repeat it
in every page). Once you have that method working the way you want it
to, it becomes highly reusable. You can change the file extension to
match whatever image types or file names you're using.

The caveat, of course, is that you have a consistent image naming
scheme. You can, of course, change the arguments to the method to pass
in the names of the images. That simplifies the entire task, and is
likely far more reliable if your file names aren't consistent. (A lack
of consistency doesn't mean anything--it's a frequent phenomenon, and
just indicates that the images likely came from disparate sources.)

I hope this helps!

Mike

Mar 14 '07 #2
On 14 Mar, 10:58, "Mike Hofer" <kchighl...@gmail.comwrote:
On Mar 14, 6:25 am, "smokeyd" <tom_bur...@umbro.co.ukwrote:
i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?

I did it on the server side, while I was setting up the page. Most of
my pages have an OK button and a Cancel button. For consistency's
sake, the images are all named the same. That is, the standard buttons
end in ".jpg" and the hover style ends in "_hover.jpg".

We use ImageButton controls to represent buttons so that we can
respond to click events server-side. When I'm designing the form, I
always only set the ImageUrl property, and I always only set it to the
*unhovered* image.

I wrote a method in the page's base class called SetButtonImages, that
looks something like this:

Protected Sub SetButtonImages(ByVal button As ImageButton)

Dim imageUrl As String

imageUrl = button.imageUrl

' Set the image that appears when the user moves the mouse off
' of the button.
image.Attributes.Add("onmouseout", "src=""" & imageUrl & """")

' Remove the .jpg extension, and add the "_hover.jpg" extension
imageUrl = imageUrl.SubString(0, imageUrl.Length - 4)
imageUrl &= "_hover.jpg"

' Set the image that appears when the user hovers the mouse
' over the image button.
button.Attributes.Add("onmouseover", "src=""" & imageUrl & """")

End Sub

(WARNING: I'm recalling this from memory, since the boss just tweaked
our firewall, and I can't peak at the source code to refresh my
memory, so I'm sorry if there are bugs.)

The method is invoked in the derived pages, like this:

Protected Sub PageLoad(ByVal sender As Object, ByVal e As EventArgs)
Handles Page.Load
...
SetButtonImages(btnOk)
SetButtonImages(btnCancel)
End Sub

This implementation saved me a lot of time, but it's based on a base
class for your pages. If you're not using a base class, you can simply
put the SetButtonImages function in a sepraate class, or even in a
module and invoke it from there (so that you don't have to repeat it
in every page). Once you have that method working the way you want it
to, it becomes highly reusable. You can change the file extension to
match whatever image types or file names you're using.

The caveat, of course, is that you have a consistent image naming
scheme. You can, of course, change the arguments to the method to pass
in the names of the images. That simplifies the entire task, and is
likely far more reliable if your file names aren't consistent. (A lack
of consistency doesn't mean anything--it's a frequent phenomenon, and
just indicates that the images likely came from disparate sources.)

I hope this helps!

Mike
works a treat!

thanks very much for that mike, it works great. cant beleive it is so
difficult in .net though!

many thanks for your help.

Mar 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard | last post by:
I'm beginning to undertake php for the fun of it. Working on a problem I hope can be solved in php. Basically what I have is this: <body> <img name="main" src="image1.jpg"> <a href="#"...
15
by: Applebrown | last post by:
I've got a couple of errors on my site that I'm not sure how to fix. I'm using simple CSS for both text rollovers and my horizontal navbar, and here's what happens. First, the site: ...
1
by: Dave | last post by:
Hi all, I was trying to make an image submit button with a rollover and discovered to my suprise that there is no way to access a form element of the "image" type. I tried specifying it by name...
1
by: Frances Del Rio | last post by:
I have a form in which submit button is an img.. would like to do it w/a rollover, but can't get rollover to work.. can you do rollovers w/img submit buttons? this is code I have: <input...
7
by: simchajoy2000 | last post by:
Hi, I am just a javascript beginner so maybe this is a simple problem but I am trying to do some rollovers on images in a separate <div>. Here is the relevent piece of my code: <html>...
1
by: trint | last post by:
Hi, I have an Image to become a link (as soon as I figure out whether it should be a button or not) that, when mousedover, changes instantly to another image. I want the image itself to be the...
2
by: Casimir | last post by:
I am looking into making pure CSS image rollovers. Do you have any clever (and robust) CSS rollover-tricks? Or links to such "in the wild"? I have figured out two methods for this, but have...
2
by: mrking | last post by:
Before I go ahead and implement this I need to confirm that what I want can be done. The standard image rollover works well, however this time I want to modify it to show the current selected...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.